<template>
	<view class="uni_box home">
		<navbar :title='title'>
		</navbar>
		<view class="content">
			<view class="list">
				<view class="item" v-for="(item,index) in list" :key="index">
					<text class="name">{{item.title}}</text>
					<text class="time">{{item.created_at}}</text>
					<u-parse class="cont" :html="item.content" :tag-style="style"></u-parse>
				</view>
				<!-- <view class="item">
					<text class="name">更换头像和简介</text>
					<text class="time">2022-01-29 15:30</text>
					<text class="cont">
						你有一份邀请好友专享288元礼包待领取！今日有效， 速去领取哟！你有一份邀请好友专享288元礼包待领 取！今日有效，速去领取哟
					</text>
				</view> -->

			</view>
			<u-loadmore :status="status" :loadText="meiyou" @loadmore="loadmore" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				page: 1,
				last_page: 1,
				limit: 10,
				status: 'loadmore',
			}
		},
		computed: {
			// 正确用法
			title() {
				return this.$t('index.zhuyi')
			},
			meiyou() {
				return {
					loadmore: this.$t('new.jiageng'),
					loading: this.$t('new.jiazai'),
					nomore: this.$t('new.meiyou')
				}
				
			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {
		},
		onReachBottom: function() {
			this.loadmore();
		},
		methods: {
			async getList(){
				let {
					list
				}= await this.$u.api.news({
					page: this.page,
					limit: this.limit,
					type:1
				});
				
				this.last_page = list.last_page;
				this.list = this.page == 1 ? list.list : [...this.list, ...list.list];
				if (this.last_page == this.page) {
					this.status = 'nomore';
				}
				// console.log(this.list)
			},
			loadmore() {
				let page = this.page;
				let last_page = this.last_page;
				if (page < last_page) {
					this.page++;
					this.getList();
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #F7F7FA;
	}
	.uni_box{
		background-color:#F7F7FA;
		min-heiht:100vh;
	}
	.content{
		background-color: #F7F7FA;
		.list{
			display: flex;
			flex-direction: column;
			padding-top: 30rpx;
			.item{
				display: flex;
				flex-direction: column;
				align-items: center;
				background: #FFFFFF;
				border-radius: 14rpx;
				padding: 40rpx;
				margin: 0 30rpx 30rpx;
				.name{
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;

				}
				.time{
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #A0A2BA;
					display: block;
					margin: 30rpx 0;
				}
				.cont{
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #666666;
				}

			}
		}
	}
</style>
